﻿//=================================================================
// Copyright © 2006 Microsoft Corporation. All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//==================================================================
// Project    : Gaee WebFramework
// Description: 
// 权限管理服务类
//  Change History:
//  When        Who         Why
//----------------------------------------------------------------
//  2011/06/06  Julian.Hu     Created. 
//
// © 2010-2011 Microsoft
// All Rights Reserved
//----------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;
using System.Data;
using System.Data.SqlClient;
using Titan.Runtiming;
using Titan.Data;
using Titan.Logging;
using GaeaWebFramework.Runtime.Core;
using GaeaWebFramework.Runtime.Core.Entities.SystemMgt;

namespace GaeaWebFramework.Runtime.Core.Services.SystemMgt
{
    public class RightMgtService : RuntimeService
    {
        #region Fields
        private static String _DBNAME = "GaeaWebFramework.DB";
        private SqlHelper sqlhelper = new SqlHelper(_DBNAME);
        private ILogger _logger = new LoggerFactory().GetLogger(typeof(RightMgtService));
        #endregion
        #region Properties
        #endregion
        #region Methods
        public RightMgtService()
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public LoginResult doLogin(string username, string password)
        {

            SM_User user = new SM_User();
            user.operator_id = username;

           List<object> userlist= sqlhelper.QueryObjects(user);

           if (userlist.Count != 1)
           {
               _logger.Debug("not only one users");
               return LoginResult.UserNameWrong;
           }
           else
           {
               SM_User userinfo = (SM_User)userlist[0];
               if (userinfo.passwd.Equals(password))
               {
                   return LoginResult.Succeed;
               }
               else
               {
                   return LoginResult.PasswordWrong;
               }
           }
        }

        //public List<sm> doGetUsersInGroups(Groups group)
        //{
        //    List<Users> result = new List<Users>();
        //    return result;
        //}

        //public List<Users> doGetUserInRoles(Roles role)
        //{
        //    return null;
        //}

        //public List<Roles> doGetRolesByUser(Users user)
        //{
        //    return null;
        //}

        //public List<Groups> doGetGroupByUser(Users user)
        //{
        //    return null;
        //}
#endregion
        #region events
        #endregion
    }
}
